package cn.heima.demo;

public class Student implements Comparable<Student> {
    private  String name ;
    private  int age ;
    private  float grade;

    public Student() {
    }

    public Student(String name, int age, float grade) {
        this.name = name;
        this.age = age;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public float getGrade() {
        return grade;
    }

    public void setGrade(float grade) {
        this.grade = grade;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", grade=" + grade +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        /*分别用Comparable和Comparator两个接口对下列四位同学的成绩做降序排序，
                如果成绩一样，那在成绩排序的基础上按照年龄由小到大排序
        * */
       int  num1  = (int)(o.getGrade()-this.getGrade());
       int  num2  = this.getAge()-o.getAge();
        return num1==0?num2:num1;
    }
}
